<?php

declare(strict_types=1);

namespace App\CustHub\Controller\Admin;

use App\CustHub\Controller\BaseController;
use App\CustHub\Service\ChPotentialUserService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\DeleteMapping;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\PutMapping;
use Mine\Annotation\Auth;
use Mine\Annotation\OperationLog;
use Mine\Annotation\Permission;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\ResponseInterface;

#[Controller(prefix: "ch/admin/potentialUser"),auth]
class ChGetPotentialUserController extends BaseController
{
    #[Inject]
    protected ChPotentialUserService $service;

    /**
     * 获取列表
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[GetMapping('index'),Permission("ch:admin:potentialUser:index")]
    public function getCaseIndustry()
    {
        return $this->success($this->service->getPageList($this->request->all()));
    }

    /**
     * 增加备注
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PutMapping('update/{id}'),Permission("ch:admin:potentialUser:update")]
    public function update($id)
    {
        $data = $this->request->all();
        return $this->service->update($id,$data)?$this->success():$this->error();
    }

    /**
     * 更改状态
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PutMapping('changeStatus'),Permission("ch:admin:potentialUser:changeStatus")]
    public function changeStatus()
    {
        $data = $this->request->all();
        return $this->service->changeStatus((int) $this->request->input('id'), (string) $this->request->input('status'))?$this->success():$this->error();
    }

    /**
     * 删除
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[deleteMapping('delete'),Permission("ch:admin:potentialUser:delete"),OperationLog]
    public function delete()
    {
        return $this->service->delete($this->request->input('ids'))?$this->success():$this->error();
    }
}